<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Struct template function</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../../xpressive/reference.html#header.boost.xpressive.regex_actions_hpp" title="Header &lt;boost/xpressive/regex_actions.hpp&gt;">
<link rel="prev" href="op/unwrap_reference/resu_1_3_48_5_3_2_1_2_18_4.html" title="Struct template result&lt;This(Ref)&gt;">
<link rel="next" href="at.html" title="Global at">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="op/unwrap_reference/resu_1_3_48_5_3_2_1_2_18_4.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../xpressive/reference.html#header.boost.xpressive.regex_actions_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="at.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.xpressive.function"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Struct template function</span></h2>
<p>boost::xpressive::function — A unary metafunction that turns an ordinary function object type into the type of a deferred function object for use in xpressive semantic actions. </p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../xpressive/reference.html#header.boost.xpressive.regex_actions_hpp" title="Header &lt;boost/xpressive/regex_actions.hpp&gt;">boost/xpressive/regex_actions.hpp</a>&gt;

</span><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <a class="link" href="../../PolymorphicFunctionObject.html" title="Concept PolymorphicFunctionObject">PolymorphicFunctionObject</a><span class="special">&gt;</span> 
<span class="keyword">struct</span> <a class="link" href="function.html" title="Struct template function">function</a> <span class="special">{</span>
  <span class="comment">// types</span>
  <span class="keyword">typedef</span> <span class="identifier">proto</span><span class="special">::</span><span class="identifier">terminal</span><span class="special">&lt;</span> <span class="identifier">PolymorphicFunctionObject</span> <span class="special">&gt;</span><span class="special">::</span><span class="identifier">type</span> <a name="boost.xpressive.function.type"></a><span class="identifier">type</span><span class="special">;</span>
<span class="special">}</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="id-1.3.48.5.4.22.4"></a><h2>Description</h2>
<p>Use <code class="computeroutput"><a class="link" href="function.html" title="Struct template function">xpressive::function</a>&lt;&gt;</code> to turn an ordinary polymorphic function object type into a type that can be used to declare an object for use in xpressive semantic actions.</p>
<p>For example, the global object <code class="computeroutput">xpressive::push_back</code> can be used to create deferred actions that have the effect of pushing a value into a container. It is defined with <code class="computeroutput"><a class="link" href="function.html" title="Struct template function">xpressive::function</a>&lt;&gt;</code> as follows:</p>
<pre class="programlisting"><span class="identifier">xpressive</span><span class="special">::</span><span class="identifier">function</span><span class="special">&lt;</span><span class="identifier">xpressive</span><span class="special">::</span><span class="identifier">op</span><span class="special">::</span><span class="identifier">push_back</span><span class="special">&gt;</span><span class="special">::</span><span class="identifier">type</span> <span class="keyword">const</span> <span class="identifier">push_back</span> <span class="special">=</span> <span class="special">{</span><span class="special">}</span><span class="special">;</span>
</pre>
<p>where <code class="computeroutput"><a class="link" href="op/push_back.html" title="Struct push_back">op::push_back</a></code> is an ordinary function object that pushes its second argument into its first. Thus defined, <code class="computeroutput">xpressive::push_back</code> can be used in semantic actions as follows:</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">xp</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">xpressive</span><span class="special">;</span>
<span class="keyword">using</span> <span class="identifier">xp</span><span class="special">::</span><span class="identifier">_</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">list</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">result</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">str</span><span class="special">(</span><span class="string">"1 23 456 7890"</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">xp</span><span class="special">::</span><span class="identifier">sregex</span> <span class="identifier">rx</span> <span class="special">=</span> <span class="special">(</span><span class="special">+</span><span class="identifier">_d</span><span class="special">)</span><span class="special">[</span> <span class="identifier">xp</span><span class="special">::</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">xp</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span><span class="special">,</span> <span class="identifier">xp</span><span class="special">::</span><span class="identifier">as</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span><span class="special">(</span><span class="identifier">_</span><span class="special">)</span> <span class="special">]</span>
    <span class="special">&gt;&gt;</span> <span class="special">*</span><span class="special">(</span><span class="char">' '</span> <span class="special">&gt;&gt;</span> <span class="special">(</span><span class="special">+</span><span class="identifier">_d</span><span class="special">)</span><span class="special">[</span> <span class="identifier">xp</span><span class="special">::</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">xp</span><span class="special">::</span><span class="identifier">ref</span><span class="special">(</span><span class="identifier">result</span><span class="special">)</span><span class="special">,</span> <span class="identifier">xp</span><span class="special">::</span><span class="identifier">as</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span><span class="special">(</span><span class="identifier">_</span><span class="special">)</span> <span class="special">)</span> <span class="special">]</span><span class="special">)</span><span class="special">;</span>
</pre>
<p> </p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2007 Eric Niebler<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="op/unwrap_reference/resu_1_3_48_5_3_2_1_2_18_4.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../xpressive/reference.html#header.boost.xpressive.regex_actions_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="at.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
